/**
 * @author Halon
 */

/*

function ConditionalAsyncHelper(timeout,callb,tries)
{
    this.timeout = timeout;
    this.callb = callb;
    this.tries = tries;
    this.success = false;
   
    var _self = this;
/*    this._timeoutCallb = function()
{
    if (_self.cond())
    {
        _self.success = true;
        _self.callb();
    }
    else
        if (_self.tries > 0)
        {
            --_self.tries;
            setTimeout(_self._timeoutCallb,_self.timeout);
        }
}
    this.call = function(condition)
    {
    alert('starting async helper');
    this.cond = condition;
    setTimeout(this.callb,this.timeout,this);
    alert('timeout set');
    }
}   
*/
/*ConditionalAsyncHelper.prototype._timeoutCallb = function()
{
    if (this.cond())
    {
        this.success = true;
        this.callb();
    }
    else
        if (this.tries > 0)
        {
            --this.tries;
            setTimeout(function(obj) { obj._timeoutCallb();},this.timeout,this);
        }
}*/
/*
ConditionalAsyncHelper.prototype.call = function(condition)
{
    alert('starting async helper');
    this.cond = condition;
    setTimeout('function(obj) { obj._timeoutCallb();}',this.timeout,this);
    alert('timeout set');
}*/
  /*  
var tmp = 5;
function conditionCheck()
{
    alert('condition checking');
    if (tmp == 0)
        return true;
    --tmp;
    return false;
}

function ca()
{
    alert('udalo sie');
}
*/
function SceneScene1(options) {
	this.options = options;
}

SceneScene1.prototype.initialize = function () {
	alert("SceneScene1.initialize()");
   
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here 
	// scene HTML and CSS will be loaded before this function is called
    
    
    this.hb = new HelpbarUserControl($('#svecKeyHelp_50Z0'))
    this.hb.addKey($.sfKey.RED,'Suggestions');
    this.hb.addKey($.sfKey.GREEN,'Profiles');
    this.hb.addKey($.sfKey.EXIT,'Exit');
    this.hb.addKey($.sfKey.BLUE,'Add Profile');
    this.hb.apply();
    
    
    if (GlobalContainer[0] == null)
        GlobalContainer[0] = new UserControlGroup('main UCG',2,1);
    this.container = GlobalContainer[0];
    alert('Initializing environment');
    this.initialized = false;
    
    this.se = GSM.get('SuggestionScreen');
    
    this.se.addMasterScene('Scene1');
    this.se.addMasterScene('Scene7');
    this.se.addMasterScene('Scene8');
    
    
    this.pe = GSM.get('ProfileEditor');
    
    this.pe.addMasterScene('Scene2');
    this.pe.addMasterScene('Scene3');
    this.pe.addScene('Scene4');
    this.pe.addScene('Scene5');
	this.pe.addScene('Scene6');
   
 //   $.sf.loadJS('JavaScript/ala.js');
   // alert($.toJSON(new Profile()));
   //  ServerProxy.getSuggestions({ 'brutality' : 5  , 'comedy' : 10 ,'romantism' : 15 , 'startTime' : 0 , 'endTime' : 13});
 //      var cah = new ConditionalAsyncHelper(1000,ca,6);
  //     cah.call(conditionCheck);*/
}




SceneScene1.prototype.handleShow = function () {
	alert("SceneScene1.handleShow()");
    
}

SceneScene1.prototype.handleHide = function () {
	alert("SceneScene1.handleHide()");
	// this function will be called when the scene manager hide this scene  
}

SceneScene1.prototype.handleFocus = function () {
	alert("SceneScene1.handleFocus()");
	// this function will be called when the scene manager focus this scene
}

SceneScene1.prototype.handleBlur = function () {
	alert("SceneScene1.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
}

SceneScene1.prototype.handleKeyDown = function (keyCode) {
	alert("SceneScene1.handleKeyDown(" + keyCode + ")");
    
    
    // ServerProxy.getSuggestions(new Profile());
    // printObject(GData.suggestionList);
    if (this.initialized == false)
    {
        this.initialized = true;
        GSM.show(this.pe);
    }
    else
    {
        if ($.sfKey.RED == keyCode) {
            GSM.show(this.pe);
			this.container = GlobalContainer[0];
        } else if ($.sfKey.GREEN == keyCode) {
            GSM.show(this.se);
			this.container = GlobalContainer[1];
		}
       
        if ($.sfKey.RETURN == keyCode)
            $.sfKey.block();
        if(this.container != null)
            this.container.handleInput(keyCode);
    }
}
